package com.freesky.web.portal.controller;

import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.web.portal.reomte.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Freesky
 */
@RestController
@Api(description = "首页页面展示")
public class HomeController {

    @Autowired
    private SearchRemote searchRemote;
    @Autowired
    private ItemRemote itemRemote;
    @Autowired
    private HomeNavRemote homeNavRemote;
    @Autowired
    private HomePanelContentRemote homePanelContentRemote;
    @Autowired
    private HomeRotationChartRemote homeRotationChartRemote;
    @Autowired
    private HomePanelRemote homePanelRemote;

    @GetMapping(value = "/home/portal/content")
    @ApiOperation(value = "获取首页内容展示")
    public JSONResponse getHomeContent() {
        return homePanelContentRemote.getHomeContent();
    }

    @GetMapping(value = "/home/nav/portal/list")
    @ApiOperation(value = "获取导航栏")
    public JSONResponse getNavList() {
        return homeNavRemote.getNavList();
    }

    @GetMapping(value = "/home/rotation-chart/portal/list")
    @ApiOperation(value = "获取首页轮播图列表")
    public JSONResponse rotationChartList() {
        return homeRotationChartRemote.portalList();
    }

    @GetMapping(value = "/home/panel/portal/recommend")
    @ApiOperation(value = "商品推荐板块")
    public JSONResponse getRecommendPanel() {
        JSONResponse recommendPanel = homePanelRemote.getRecommendPanel();
        System.out.println(recommendPanel);
        return recommendPanel;
    }

    @GetMapping(value = "/home/panel/portal/thanks")
    @ApiOperation(value = "获取捐赠板块")
    public JSONResponse getThanksPanel() {
        return homePanelRemote.getThanksPanel();
    }

    @GetMapping(value = "/item/detail")
    @ApiOperation(value = "商品详情")
    public JSONResponse getItemDetail(@RequestParam(value = "productId") String id) {
        return itemRemote.getItemDetail(id);
    }

    @GetMapping(value = "/item/get_all")
    public JSONResponse getAll(
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "size", defaultValue = "20") int size,
            @RequestParam(value = "sort", defaultValue = "") String sort,
            @RequestParam(value = "cid", defaultValue = "") Long cid,
            @RequestParam(value = "priceGt", defaultValue = "-1") int priceGt,
            @RequestParam(value = "priceLte", defaultValue = "-1") int priceLte) {

        return itemRemote.getAll(page, size, sort, cid, priceGt, priceLte);
    }

    @GetMapping(value = "/item/search")
    @ApiOperation(value = "搜索商品")
    public JSONResponse searchProduct(
            @RequestParam(defaultValue = "") String key,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "20") int size,
            @RequestParam(defaultValue = "") String sort,
            @RequestParam(defaultValue = "-1") int priceGt,
            @RequestParam(defaultValue = "-1") int priceLte) {
        return searchRemote.searchProduct(key, page, size, sort, priceGt, priceLte);
    }

    @GetMapping(value = "/item/search/item_name_list")
    @ApiOperation(value = "快速搜索")
    public JSONResponse getItemNameListByKeyWords(@RequestParam(value = "key", defaultValue = "") String key) {
        return searchRemote.getItemNameListByKeyWords(key);
    }
}
